package member

import (
	"stormragetech/dawn/data"
	"time"

	"gopkg.in/mgo.v2/bson"
)

func init() {
	data.GetConn("test", "sys_user")
}

// SysUser user 结构体
type SysUser struct {
	ID         bson.ObjectId `bson:"_id"`
	UserID     string        `bson:"u_id"`
	Username   string        `bson:"username"`
	Password   string        `bson:"password"`
	Salt       string        `bson:"salt"`
	Realname   string        `bson:"realname"`
	PosID      string        `bson:"pos_id"`
	CreateDate time.Time     `bson:"c_date"`
	Locked     bool          `bson:"locked"`
}

// InsUser 新增用户
func InsUser(u SysUser) error {
	return data.Conn.Insert(u)
}

// FindByUsername 通过用户名查询用户
func FindByUsername(name string) (SysUser, error) {
	user := SysUser{}
	err := data.Conn.Find(bson.M{"username": name}).One(&user)
	return user, err
}
